package com.go.where.manager.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.go.where.manager.common.Constants;
import com.go.where.manager.dao.CourseRetrospectDao;
import com.go.where.manager.page.Pagination;
import com.go.where.manager.pojo.CourseRetrospectInfo;
import com.go.where.manager.pojo.user.UserInfoVO;
import com.go.where.manager.service.CourseRetrospectService;

@Service("courseRetrospectService")
public class CourseRetrospectServiceImpl implements CourseRetrospectService {

	@Resource(name = "courseRetrospectDao")
	private CourseRetrospectDao courseRetrospectDao;

	@Override
	public CourseRetrospectInfo queryByPrimartKey(String cid) {
		return courseRetrospectDao.getByKey(cid);
	}

	@Override
	public Pagination<CourseRetrospectInfo> queryPage(
			CourseRetrospectInfo retorspectInfo) {
		Integer count = courseRetrospectDao.totalCount(retorspectInfo);
		retorspectInfo.calculate();
		List<CourseRetrospectInfo> list = courseRetrospectDao
				.queryList(retorspectInfo);
		Pagination<CourseRetrospectInfo> page = courseRetrospectDao
				.queryPagination(count, list, retorspectInfo);
		return page;
	}

	@Override
	public int save(CourseRetrospectInfo retorspectInfo, UserInfoVO currentUser) {
		retorspectInfo.setPublishTime(new Date());
		retorspectInfo.setUserId(currentUser.getUserId());
		retorspectInfo.setIsDelete(Constants.NOT_DELETED);
		return courseRetrospectDao.insert(retorspectInfo);
	}

	@Override
	public int update(CourseRetrospectInfo retorspectInfo,
			UserInfoVO currentUser) {
		retorspectInfo.setUpdateTime(new Date());
		retorspectInfo.setUserId(currentUser.getUserId());
		return courseRetrospectDao.update(retorspectInfo);
	}

}
